package com.hubox.customvalidator;


import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class CustomValidator implements ConstraintValidator<CustomCheck, String> {
    private Mode mode;

    @Override
    public void initialize(CustomCheck customCheck) {
        mode=customCheck.mode();
    }

    @Override
    public boolean isValid(String customField, ConstraintValidatorContext cxt) {
//        throw new IllegalArgumentException("something error ");//will throw ValidationException, should handle ValidationException
        if(Mode.UPPER.equals(mode)){
            return "SZ".equals(customField) || "BJ".equals(customField);
        }
        if(Mode.LOWER.equals(mode)){
            return "sz".equals(customField) || "bj".equals(customField);
        }
        return false;
    }
}
